package com.qianbao.qianbaobusiness.ui.cashier;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baseandroid.config.Constant;
import com.baseandroid.mvp.BaseMvpActivity;
import com.baseandroid.utils.TimeUtils;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.AboutSettlementBean;
import com.qianbao.qianbaobusiness.json.AboutSettlementListBean;
import com.qianbao.qianbaobusiness.json.SettlementDetailBean;
import com.qianbao.qianbaobusiness.ui.cashier.databill.DataBillOldActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class DataBillActivity extends BaseMvpActivity<DataBillView, DataBillPresenter> implements DataBillView {
    @BindView(R.id.toolbar_back)
    RelativeLayout toolbarBack;    //返回
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;     //标题
    @BindView(R.id.data_bill_calendar_amount_tv)
    TextView dataBillCalendarAmountTv;
    @BindView(R.id.data_bill_calendar_tv)
    TextView dataBillCalendarTv;
    @BindView(R.id.tv_weixin_money)
    TextView tv_weixin_money;
    @BindView(R.id.tv_polymerized_money)
    TextView tv_polymerized_money;
    @BindView(R.id.tv_qianbao_money)
    TextView tv_qianbao_money;
    @BindView(R.id.data_bill_screen_rv)
    ListView data_bill_screen_rv;
    @BindView(R.id.layout_empty)
    LinearLayout layout_empty;
    private String chkAccountDate;     //日期
    private SettlementDetailBean.SettleMent mbean;
    private DataSettlementAdapter adapter;
    private List<AboutSettlementBean> beanList;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_data_bill;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void setupView() {
        beanList = new ArrayList<>();
        mbean = (SettlementDetailBean.SettleMent) getIntent().getSerializableExtra("bean");
        chkAccountDate = TimeUtils.getDate(mbean.getSettleDate(), Constant.DATE_YYYYMMDD, Constant.DATE_YYYY_MM_DD);
        toolbarTitle.setText(chkAccountDate);
        dataBillCalendarTv.setText("应到账总金额（元）");
        getPresenter().getQueryDayChecking(chkAccountDate, mbean.merchantCode);
        getPresenter().getSettleDetail(chkAccountDate, mbean.merchantCode);
        adapter = new DataSettlementAdapter(this, beanList);
        data_bill_screen_rv.setAdapter(adapter);
        dataBillCalendarAmountTv.setText((Double.parseDouble(mbean.getTotalAmt()) / 100) + "");
        tv_weixin_money.setText((Double.parseDouble(mbean.getAlipayAmt()) / 100 + Double.parseDouble(mbean
                .getWechatAmt()) / 100) + "");
        tv_polymerized_money.setText((Double.parseDouble(mbean.getPOSAmt()) / 100 + ""));
        tv_qianbao_money.setText((Double.parseDouble(mbean.getQianbaoAmt()) / 100 + ""));

        data_bill_screen_rv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Bundle bundle = new Bundle();
                bundle.putString("chkAccountDate", beanList.get(position)
                        .getChkAccountDate());
                bundle.putString("postMerchantNo", mbean.merchantCode);
                Intent intent = new Intent();
                intent.putExtras(bundle);
                 intent.setClass(DataBillActivity.this, DataBillOldActivity.class);
                 startActivity(intent);
            }
        });
    }

    @Override
    protected void setupData(Bundle savedInstanceState) {

    }

    @OnClick({R.id.toolbar_back})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.toolbar_back:
                finish();
                break;
        }
    }

    @Override
    public void onComplete() {

    }

    @Override
    public void onSuccess(AboutSettlementListBean bean) {
        if (bean != null && bean.size() > 0) {
            beanList.addAll(bean);
            adapter.notifyDataSetChanged();
        } else {
            if (beanList.size() == 0) {
                data_bill_screen_rv.setVisibility(View.GONE);
                layout_empty.setVisibility(View.VISIBLE);
            }
        }
    }

    @Override
    public void onSuccess(SettlementDetailBean bean) {

    }

}
